<?php

namespace App\Services;

use Zookeeper;

/**
* Zookeeper 服务实现类
*/
class ZookeeperService extends Zookeeper
{
    const PATH = '/isakura';
    
    /**
     * 访问控制
     * @var array
     */
    private $_acl = array(
        array(
            'perms'     => Zookeeper::PERM_ALL,
            'scheme'    => 'world',
            'id'        => 'anyone',
        ),
    );

    public function init( $path = self::PATH )
    {
        if ( $this->exists( $path ) )
            $this->delete( $path );
        $this->create( $path, 'init', $this->_acl );
        // 设置当前节点监听
        var_dump( $this->get( $path, array( $this, 'watch' ) ) );
        // 设置当前节点的子节点情况监听
        $childArr = $this->getChildren( $path, array( $this, 'watchChildren' ) );
        var_dump( $childArr );
        // foreach ( $childArr as $value )
        //     $this->get( $path . '/' . $value, array( $this, 'watch' ) );
    }
}